package com.example.adminui.controller;

/**
 * 客户控制器
 * 处理客户相关的HTTP请求
 */

import com.example.adminui.entity.Customer;
import com.example.adminui.service.CustomerService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/customers")
public class CustomerController {

    /**
     * 客户服务接口
     */
    @Autowired
    private CustomerService customerService;

    /**
     * 获取所有客户信息
     * @return 客户列表
     */

    @GetMapping
    public List<Customer> getAllCustomers() {
        return customerService.getAllCustomers();
    }

        /**
     * 根据ID获取客户信息
     * @param id 客户ID
     * @return 客户信息
     */
    @GetMapping("/{id}")
    public Customer getCustomerById(@PathVariable Long id) {
        return customerService.getCustomerById(id);
    }

        /**
     * 创建新客户
     * @param customer 客户信息
     */
    @PostMapping
    public void createCustomer(@RequestBody Customer customer) {
        customerService.createCustomer(customer);
    }

        /**
     * 更新客户信息
     * @param id 客户ID
     * @param customer 客户信息
     */
    @PutMapping("/{id}")
    public void updateCustomer(@PathVariable Long id, @RequestBody Customer customer) {
        customer.setId(id);
        customerService.updateCustomer(customer);
    }

        /**
     * 删除客户
     * @param id 客户ID
     */
    @DeleteMapping("/{id}")
    public void deleteCustomer(@PathVariable Long id) {
        customerService.deleteCustomer(id);
    }

    /**
     * 根据客户信息进行查询
     * */
    @GetMapping("/query")
    public List<Customer> queryCustomer(){
        return customerService.queryCustomer();
    }

}